template<class Iterator, class Ref, class Ptr>
class __reverse_iterator
{
public:
	typedef __reverse_iterator<Iterator, Ref, Ptr> Self;
	Iterator iterator;

	__reverse_iterator(const Iterator& it) :iterator(it) {}

	Self& operator++() {
		--iterator;
		return *this;
	}
	Self operator++(int) {
		Self tmp(iterator);
		--iterator;
		return tmp;
	}

	Self& operator--() {
		++iterator;
		return *this;
	}
	Self operator--(int) {
		Self tmp(iterator);
		++iterator;
		return tmp;
	}

	Ref operator*()
	{
		Iterator tmp = iterator;
		return *--tmp;
	}
	Ptr operator->()
	{
		return &(operator*());
	}

	bool operator==(const Self& rit) const { return iterator == rit.iterator; }
	bool operator!=(const Self& rit) const { return iterator != rit.iterator; }
};

